package com.app.shop.controller.wx;

import com.app.shop.controller.system.BaseController;
import com.app.shop.dao.wg.WgCommodityMapper;
import com.app.shop.dao.wg.WgFocusMapper;
import com.app.shop.dao.wg.WgPictureMapper;
import com.app.shop.dao.wg.WgSystemMapper;
import com.app.shop.entity.*;
import com.app.shop.entity.show.WxHomeShow;
import com.app.shop.entity.show.WxModel;
import com.app.shop.service.shop.WgCommodityService;
import com.app.shop.service.shop.WgTearmService;
import com.app.shop.util.ApiRest;
import com.app.shop.util.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;


/**
 * 首页数据展示处理Controller模块
 *
 * @author chenliwei
 * @version v1.0 2017-11-5
 */
@Controller
@RequestMapping(value = "/api/home")
public class WxHomeController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(WxHomeController.class);

    @Autowired
    public WgTearmService wgTearmService;
    @Autowired
    public WgSystemMapper wgSystemMapper;
    @Autowired
    public WgCommodityMapper wgCommodityMapper;
    @Autowired
    public WgPictureMapper wgPictureMapper;
    @Autowired
    public WgFocusMapper wgFocusMapper;
    @Autowired
    public WgCommodityService wgCommodityService;

    /**
     * 首页图片,首页教练列表，体验课活动主图，首页地址，首页联系电话信息，健身环境主图
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getInitData")
    public ApiRest getInitData() throws  Exception{


        WgSystem wgSystem =wgSystemMapper.selectByPrimaryKey(1);
        WxHomeShow wx=new WxHomeShow();
        //轮播图
        List<WxModel> bannerListImg =new ArrayList<WxModel>();
        WgFocusExample wgFocusExample = new WgFocusExample();
        WgFocusExample.Criteria criteria = wgFocusExample.createCriteria();
        criteria.andDeleteFlagEqualTo(1);
        List<WgFocus> wgFocusList = wgFocusMapper.selectByExample(wgFocusExample);
        for (WgFocus wgfocus: wgFocusList) {
            bannerListImg.add(new WxModel(wgfocus.getId(),wgfocus.getTitle(),wgfocus.getPictureUrl()));
        }
        wx.setBannerListImg(bannerListImg);
        //活动1
        WgCommodity wgCommodity = wgCommodityMapper.selectByPrimaryKey(Integer.parseInt(wgSystem.getHuodongOne()));
        wx.setHuodong1(new WxModel(wgCommodity.getId(),wgCommodity.getName(),wgPictureMapper.getUrlbyId(wgCommodity.getPictureId())));
        //活动2
        wx.setHuodong2(new WxModel("健身环境","http://127.0.0.1:9999/static/image/banner3.jpg"));
        //教练团队
        List<WxModel> treamListImg =wgTearmService.getTearmList();
        wx.setTearmList(treamListImg);
        //位置
        wx.setAddress(wgSystem.getAddress());
        //联系电话
        wx.setPhone(wgSystem.getPhone());
        return new ApiRest(Constant.REST_SUCCESS_CODE, Constant.SUCCESS_MESSAGE, wx);
    }


    /**
     * 教练信息列表
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getTearmList")
    public ApiRest getTearmList() throws  Exception{
        List<WxModel> treamListImg =wgTearmService.getTearmList();
//        treamListImg.add(new WxModel("张教练","店长",3,"从业9年|擅长：减肥、减肥、减肥","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553187020783&di=bac9dd78b36fd984502d404d231011c0&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201609%2F26%2F20160926173213_s5adi.jpeg"));
//        treamListImg.add(new WxModel("张教练","教练",3,"从业9年|擅长：减肥、减肥、减肥","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553187020783&di=bac9dd78b36fd984502d404d231011c0&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201609%2F26%2F20160926173213_s5adi.jpeg"));
//        treamListImg.add(new WxModel("张教练","教练",3,"从业9年|擅长：减肥、减肥、减肥","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553187020783&di=bac9dd78b36fd984502d404d231011c0&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201609%2F26%2F20160926173213_s5adi.jpeg"));
        return new ApiRest(Constant.REST_SUCCESS_CODE, Constant.SUCCESS_MESSAGE, treamListImg);
    }

    /**
     * 环境列表
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getAmbientList")
    public ApiRest getAmbientList() {
        List<WxModel> ambientListImg =new ArrayList<WxModel>();
        ambientListImg.add(new WxModel("健身场馆","http://127.0.0.1:9999/static/image/banner1.jpg"));
        ambientListImg.add(new WxModel("游泳健身","http://127.0.0.1:9999/static/image/banner2.jpg"));
        ambientListImg.add(new WxModel("减肥抽脂","http://127.0.0.1:9999/static/image/banner3.jpg"));
        ambientListImg.add(new WxModel("燃烧卡路里","http://127.0.0.1:9999/static/image/banner4.jpg"));
        return new ApiRest(Constant.REST_SUCCESS_CODE, Constant.SUCCESS_MESSAGE, ambientListImg);
    }

    /**
     * 体验课信息列表
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getCourseList")
    public ApiRest getCourseList() {
        List<WxModel> courseListImg =new ArrayList<WxModel>();
        List<WgCommodity> wgCommodities =wgCommodityMapper.queryWgCommodityList();
        for (WgCommodity wgCommodity:wgCommodities) {
            courseListImg.add(new WxModel(wgCommodity.getId(),wgCommodity.getName(),wgPictureMapper.getUrlbyId(wgCommodity.getPictureId()),wgCommodity.getPrice().doubleValue(),wgCommodity.getPriceOld().doubleValue()));
        }
        return new ApiRest(Constant.REST_SUCCESS_CODE, Constant.SUCCESS_MESSAGE, courseListImg);
    }



    /**
     * 教练个人信息，以及个人相关活动
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getTearmInfo")
    public ApiRest getTearmInfo() {

        return new ApiRest(Constant.REST_SUCCESS_CODE, Constant.SUCCESS_MESSAGE, "调用成功");
    }
}